#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qtoolbar.h"
#include "qtoolbutton.h"
#include "../../Source/hcview.h"
#include "QVBoxLayout"
#include "qmenubar.h"
#include "qstatusbar.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("HCView C++");

    this->initMenu();
    this->initToolBar();

    HCView *vHCView = new HCView(this);
    this->setCentralWidget(vHCView);

    statusBar()->showMessage(tr("Ready"));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initMenu()
{
    QMenu *fileMenu = menuBar()->addMenu(tr("文件"));
    QMenu *editMenu = menuBar()->addMenu(tr("编辑"));
}

void MainWindow::initToolBar()
{
    QToolBar *toolBar = addToolBar(tr("&toolbar"));
    toolBar->setIconSize(QSize(16, 16));

    int vBtnWidth = 24;
    // 打开菜单
    QToolButton *btnOpen = new QToolButton(toolBar);
    btnOpen->setPopupMode(QToolButton::MenuButtonPopup);
    btnOpen->setIcon(QIcon(":/Resources/fold.ico"));
    toolBar->addWidget(btnOpen);

    // 保存按钮
    QToolButton *btnSave = new QToolButton(toolBar);
    btnSave->setIcon(QIcon(":/Resources/save.ico"));
    btnSave->setText("保存");
    btnSave->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    toolBar->addWidget(btnSave);

    // 加粗按钮
    QToolButton *btnBold = new QToolButton(toolBar);
    btnBold->setIcon(QIcon(":/Resources/bold.ico"));
    btnBold->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnBold->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnBold);

    // 倾斜按钮
    QToolButton *btnItalic = new QToolButton(toolBar);
    btnItalic->setIcon(QIcon(":/Resources/italic.ico"));
    btnItalic->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnItalic->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnItalic);

    // 下划线按钮
    QToolButton *btnUnderLine = new QToolButton(toolBar);
    btnUnderLine->setIcon(QIcon(":/Resources/underline.ico"));
    btnUnderLine->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnUnderLine->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnUnderLine);

    // 中划线按钮
    QToolButton *btnStrikeout = new QToolButton(toolBar);
    btnStrikeout->setIcon(QIcon(":/Resources/strikeout.ico"));
    btnStrikeout->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnStrikeout->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnStrikeout);

    // 上标按钮
    QToolButton *btnSuperscript = new QToolButton(toolBar);
    btnSuperscript->setIcon(QIcon(":/Resources/superscript.ico"));
    btnSuperscript->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnSuperscript->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnSuperscript);

    // 下标按钮
    QToolButton *btnSubscript = new QToolButton(toolBar);
    btnSubscript->setIcon(QIcon(":/Resources/subscript.ico"));
    btnSubscript->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnSubscript->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnSubscript);

    // 右缩进按钮
    QToolButton *btnRightindent = new QToolButton(toolBar);
    btnRightindent->setIcon(QIcon(":/Resources/rightindent.ico"));
    btnRightindent->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnRightindent->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnRightindent);

    // 左缩进按钮
    QToolButton *btnLeftindent = new QToolButton(toolBar);
    btnLeftindent->setIcon(QIcon(":/Resources/leftindent.ico"));
    btnLeftindent->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnLeftindent->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnLeftindent);

    // 左对齐按钮
    QToolButton *btnAlignleft = new QToolButton(toolBar);
    btnAlignleft->setIcon(QIcon(":/Resources/alignleft.ico"));
    btnAlignleft->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnAlignleft->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnAlignleft);

    // 居中对齐按钮
    QToolButton *btnAligncenter = new QToolButton(toolBar);
    btnAligncenter->setIcon(QIcon(":/Resources/aligncenter.ico"));
    btnAligncenter->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnAligncenter->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnAligncenter);

    // 右对齐按钮
    QToolButton *btnAlignright = new QToolButton(toolBar);
    btnAlignright->setIcon(QIcon(":/Resources/alignright.ico"));
    btnAlignright->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnAlignright->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnAlignright);

    // 分散对齐按钮
    QToolButton *btnAlignjustify = new QToolButton(toolBar);
    btnAlignjustify->setIcon(QIcon(":/Resources/alignjustify.ico"));
    btnAlignjustify->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnAlignjustify->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnAlignjustify);

    // 两端对齐按钮
    QToolButton *btnAlignscatter = new QToolButton(toolBar);
    btnAlignscatter->setIcon(QIcon(":/Resources/alignscatter.ico"));
    btnAlignscatter->setToolButtonStyle(Qt::ToolButtonIconOnly);
    btnAlignscatter->setFixedWidth(vBtnWidth);
    toolBar->addWidget(btnAlignscatter);

    // 行间距
    QToolButton *btnLinespace = new QToolButton(toolBar);
    btnLinespace->setPopupMode(QToolButton::MenuButtonPopup);
    btnLinespace->setIcon(QIcon(":/Resources/linespace.ico"));
    btnLinespace->setToolButtonStyle(Qt::ToolButtonIconOnly);
    toolBar->addWidget(btnLinespace);
}
